package org.pie.drawing.apps.picimageserver.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.pie.drawing.apps.picimageserver.dto.ImageSearchDTO;
import org.pie.drawing.apps.picimageserver.entity.ImageIndexEntity;
import org.pie.drawing.apps.picimageserver.service.ImageIndexService;
import org.pie.drawing.apps.picimageserver.utils.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequiredArgsConstructor
@Api(tags = "图片查询")
@RestController
@RequestMapping(value = "image")
public class ImageSearchController {

    private final ImageIndexService imageIndexService;

    @ApiOperation("图片预览")
    @GetMapping(value = "search")
    public void search(ImageSearchDTO dto, HttpServletResponse response) {
        imageIndexService.searchImageIndex(dto, response);
    }

    @ApiOperation("图片预览")
    @GetMapping(value = "searchById/{id}")
    public void searchById(@PathVariable("id") Long id, HttpServletResponse response) {
        imageIndexService.searchById(id, response);
    }

    @ApiOperation("获取图片索引列表")
    @GetMapping(value = "list")
    public R list(ImageSearchDTO dto) {
        List<ImageIndexEntity> list = imageIndexService.list(dto);
        return R.ok(list);
    }

    @ApiOperation("获取最新图片索引")
    @GetMapping(value = "newestImage")
    public R newestImage(ImageSearchDTO dto) {
        ImageIndexEntity entity = imageIndexService.newestImage(dto);
        return R.ok( entity);
    }

    @ApiOperation("数据时次列表")
    @GetMapping(value = "hourList")
    public R hourList(ImageSearchDTO dto) {
        List<String> list = imageIndexService.hourList(dto);
        return R.ok( list);
    }
}
